package com.sts.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sts.dto.TicketStatusFlowDTO;
import com.sts.entity.TicketStatusFlow;
import com.sts.mapper.TicketStatusFlowMapper;
import com.sts.service.TicketStatusFlowService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class TicketStatusFlowServiceImpl implements TicketStatusFlowService {

    private final TicketStatusFlowMapper flowMapper;

    @Override
    public List<TicketStatusFlowDTO> listByTicket(Long ticketId) {
        return flowMapper.selectList(
                        Wrappers.<TicketStatusFlow>lambdaQuery()
                                .eq(TicketStatusFlow::getTicketId, ticketId)
                                .orderByDesc(TicketStatusFlow::getId))
                .stream()
                .map(f -> BeanUtil.copyProperties(f, TicketStatusFlowDTO.class))
                .collect(Collectors.toList());
    }
}